package com.hy.lightning.commons.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	
	public static void main(String[] args) {
		Date now = new Date();
		System.out.println(DateUtil.toString(now, "yyyy-MM-dd")+" 24:00:00");
		long init_time = DateUtil.compare(DateUtil.toDate(DateUtil.toString(now, "yyyy-MM-dd")+" 24:00:00", "yyyy-MM-dd HH:mm:ss") , now);
		System.out.println(init_time/1000/60/59);
	}

	public static String toString(Date date) {
		return toString(date, "yyyy-MM-dd HH:mm:ss");
	}
	
	public static String toString(Date date, String format) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		return simpleDateFormat.format(date);
	}

	public static Date toDate(String str) throws ParseException {
		return toDate(str, "yyyy-MM-dd HH:mm:ss");
	}
	
	public static Date toDate(String str, String format) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		try {
			return simpleDateFormat.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static long compare(Date date1, Date date2) {
		return date1.getTime() - date2.getTime();
	}
}
